<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <h:body>

        <ui:composition template="/resources/template/template.xhtml">

            <ui:define name="content">
                <h:form>
                    <p:panelGrid columns="1" >
                        <p:panelGrid columns="2" >
                            <h:outputLabel value="Select Investigation" />
                            <p:autoComplete converter="ixcon" widgetVar="aIx" id="acIx" forceSelection="true" value="#{testFlagController.investigation}" completeMethod="#{investigationController.completeInvest}" var="ix" itemLabel="#{ix.name}" itemValue="#{ix}" size="30"  style="width: 400px;">
                                <p:ajax event="itemSelect" process="acIx" update="iif iiv tbl" />
                            </p:autoComplete>

                            <h:outputLabel value="Select Flag" ></h:outputLabel>
                            <p:selectOneMenu id="iif" value="#{testFlagController.investigationItemofFlagType}" >
                                <f:selectItem itemLabel="Select a Flag"/>
                                <f:selectItems value="#{testFlagController.investigationItemsOfFlagType}" var="iifs" itemLabel="#{iifs.name}" itemValue="#{iifs}" />
                            </p:selectOneMenu>
                            <h:outputLabel value="Select Value" ></h:outputLabel>
                            <p:selectOneMenu id="iiv" value="#{testFlagController.investigationItemOfValueType}" >
                                <f:selectItem itemLabel="Select a Value"/>
                                <f:selectItems value="#{testFlagController.investigationItemsOfValueType}" var="iivs" itemLabel="#{iivs.name}" itemValue="#{iivs}" />
                            </p:selectOneMenu>
                            <h:outputLabel value="Sex" ></h:outputLabel>
                            <p:selectOneMenu id="txtNewSex"  value="#{testFlagController.sex}" style="width: 200px;">
                                <f:selectItem itemLabel="Select Sex"/>
                                <f:selectItem itemLabel="Male" itemValue="Male"/>
                                <f:selectItem itemLabel="Female" itemValue="Female"/>
                            </p:selectOneMenu>
                            <h:outputLabel value="From Age" ></h:outputLabel>
                            <h:panelGrid columns="2">
                                <p:inputText autocomplete="off" value="#{testFlagController.fromAge}"></p:inputText>
                                <h:selectOneMenu value="#{testFlagController.fromAgeUnit}" >
                                    <f:selectItem itemLabel="Days" itemValue="Days"/>
                                    <f:selectItem itemLabel="Months" itemValue="Months"/>
                                    <f:selectItem itemLabel="Years" itemValue="Years"/>
                                </h:selectOneMenu>
                            </h:panelGrid>
                            <h:outputLabel value="To Age" ></h:outputLabel>
                            <h:panelGrid columns="2">
                                <p:inputText autocomplete="off" value="#{testFlagController.toAge}"></p:inputText>
                                <h:selectOneMenu value="#{testFlagController.toAgeUnit}" >
                                    <f:selectItem itemLabel="Days" itemValue="Days"/>
                                    <f:selectItem itemLabel="Months" itemValue="Months"/>
                                    <f:selectItem itemLabel="Years" itemValue="Years"/>
                                </h:selectOneMenu>
                            </h:panelGrid>

                            <h:outputLabel value="From Value" ></h:outputLabel>
                            <p:inputText autocomplete="off" value="#{testFlagController.fromValue}"></p:inputText>

                            <h:outputLabel value="To Value" ></h:outputLabel>
                            <p:inputText autocomplete="off" value="#{testFlagController.toValue}"></p:inputText>

                            <h:outputLabel value="Message if Low" ></h:outputLabel>
                            <p:inputTextarea value="#{testFlagController.lowMessage }" ></p:inputTextarea>
                            <h:outputLabel value="Message if High" ></h:outputLabel>
                            <p:inputTextarea value="#{testFlagController.highMessage }" ></p:inputTextarea>
                            <h:outputLabel value="Message if Within the Range" ></h:outputLabel>
                            <p:inputTextarea value="#{testFlagController.flagMessage }" ></p:inputTextarea>
                            <p:commandButton ajax="false" value="Save" action="#{testFlagController.addFlag()}" onclick="onSubmitButton();" />
                        </p:panelGrid>

                        <p:panelGrid columns="1" >

                            <p:dataTable id="tbl" value="#{testFlagController.items}" editable="true" var="f" >
                                <p:ajax event="rowEdit" listener="#{testFlagController.onEdit}"  /> 


                                <p:column headerText="Investigation">
                                    #{f.item.name}
                                </p:column>
                                <p:column headerText="Flag Field">
                                    #{f.investigationItemOfFlagType.name}
                                </p:column>
                                <p:column headerText="Value Field">
                                    #{f.investigationItemOfValueType.name}
                                </p:column>
                                <p:column headerText="Sex">  
                                    <p:cellEditor>  
                                        <f:facet name="output">  
                                            <h:outputText value="#{f.sex}" />  
                                        </f:facet>  
                                        <f:facet name="input">  
                                            <p:selectOneMenu value="#{f.sex}" style="width: 200px;">
                                                <f:selectItem itemLabel="Select Sex"/>
                                                <f:selectItem itemLabel="Male" itemValue="Male"/>
                                                <f:selectItem itemLabel="Female" itemValue="Female"/>
                                            </p:selectOneMenu>
                                        </f:facet>  
                                    </p:cellEditor>    

                                </p:column>
                                <p:column headerText="From Age">
                                    <p:cellEditor>  
                                        <f:facet name="output">  
                                            <h:outputText value="#{f.fromAge}" />  
                                        </f:facet>  
                                        <f:facet name="input">  
                                            <h:inputText autocomplete="off" value="#{f.fromAge}"/>  
                                        </f:facet>  
                                    </p:cellEditor>                                     
                                </p:column>
                                <p:column headerText="To Age">
                                    <p:cellEditor>  
                                        <f:facet name="output">  
                                            <h:outputText value="#{f.toAge}" />  
                                        </f:facet>  
                                        <f:facet name="input">  
                                            <h:inputText autocomplete="off" value="#{f.toAge}"/>  
                                        </f:facet>  
                                    </p:cellEditor> 

                                </p:column>

                                <p:column headerText="From Value">
                                    <p:cellEditor>  
                                        <f:facet name="output">  
                                            <h:outputText value="#{f.fromVal}" />  
                                        </f:facet>  
                                        <f:facet name="input">  
                                            <h:inputText autocomplete="off" value="#{f.fromVal}"/>  
                                        </f:facet>  
                                    </p:cellEditor>                                    
                                </p:column>

                                <p:column headerText="To Value">
                                    <p:cellEditor>  
                                        <f:facet name="output">  
                                            <h:outputText value="#{f.toVal}" />  
                                        </f:facet>  
                                        <f:facet name="input">  
                                            <h:inputText autocomplete="off" value="#{f.toVal}"/>  
                                        </f:facet>  
                                    </p:cellEditor>                                       
                                </p:column>

                                <p:column headerText="High Message">
                                    <p:cellEditor>  
                                        <f:facet name="output">  
                                            <h:outputText value="#{f.highMessage}" />  
                                        </f:facet>  
                                        <f:facet name="input">  
                                            <h:inputText autocomplete="off" value="#{f.highMessage}"/>  
                                        </f:facet>  
                                    </p:cellEditor>  

                                </p:column>

                                <p:column headerText="Low Message">
                                    <p:cellEditor>  
                                        <f:facet name="output">  
                                            <h:outputText value="#{f.lowMessage}" />  
                                        </f:facet>  
                                        <f:facet name="input">  
                                            <h:inputText autocomplete="off" value="#{f.lowMessage}"/>  
                                        </f:facet>  
                                    </p:cellEditor>                                    
                                </p:column>

                                <p:column headerText="Normal Message">
                                    <p:cellEditor>  
                                        <f:facet name="output">  
                                            <h:outputText value="#{f.flagMessage}" />  
                                        </f:facet>  
                                        <f:facet name="input">  
                                            <h:inputText autocomplete="off" value="#{f.flagMessage}"/>  
                                        </f:facet>  
                                    </p:cellEditor>                                        
                                </p:column>


                                <p:column headerText="Report Item id">
                                    #{f.investigationItemOfFlagType.id}
                                    <br/>
                                    #{f.retired}
                                </p:column>


                                <p:column style="width:6%">  
                                    <p:rowEditor > 

                                    </p:rowEditor>
                                </p:column>            

                                <p:column headerText="Remove">
                                    <h:commandButton value="Remove" action="#{testFlagController.removeFlag}" >
                                        <f:setPropertyActionListener value="#{f}" target="#{testFlagController.removingFlag}" />
                                    </h:commandButton>
                                </p:column>



                            </p:dataTable>

                        </p:panelGrid>


                    </p:panelGrid>




                </h:form>
            </ui:define>


        </ui:composition>

    </h:body>
</html>
